import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//unplugin-vue-components 插件来按需自动加载组件
//注意，这种方法并不会处理函数 API，比如 useMessage，用户仍需要手动导入对应 API，例如 import { useMessage } from 'naive-ui'。
const path = require('path');

import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [NaiveUiResolver()]
    })
  ],
  resolve: {
    // 配置路径别名
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  server: {
    proxy: {
      '/360api': {
        // target: 'http://wallpaper.apc.360.cn/',
        target: 'http://localhost:9000/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/360api/, '')
      },
      '/bingapi': {
        target: 'https://api.codelife.cc/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/bingapi/, '')
      }
    }
  }
})
